<?php

class Application_Model_DbTable_User extends Zend_Db_Table_Abstract
{

    protected $_name = 'users';
    
     protected $_dependentTables = array(
        "Application_Model_DbTable_Contact",
        "Application_Model_DbTable_OnlineSupport",
        "Application_Model_DbTable_Article"
     );
    
    protected $_referenceMap = array(
        "Group" => array(
            'columns' => "groups_id",
            'refTableClass' => "Application_Model_DbTable_UserGroup",
            'refColumns'=>"idgroups",
            'onUpdate' => self::RESTRICT,
            'onDelete' => self::RESTRICT
        )
    );
    
    public function fetchPaginatorAdapter($filters=array(), $sortField = null, $sortType="asc")
    {
        $select = $this->select();
        
        //filter
        if(count($filters)>0)
        {
            foreach($filters as $field=>$filter)
            {
                if(is_string($filter))
                {
                    $select->where("$field LIKE '%$filter%'");
                }
                else
                {
                    $select->where("$field=?", $filter);
                }
            }
        }
        
        //sort
        if(null != $sortField)
        {
            $select->order($sortField." ".$sortType);
        }
        
        $adapter = new Zend_Paginator_Adapter_DbTableSelect($select);
        return $adapter;
    }

}

